/**
 * Created by gongxun on 17/6/2.
 */

var KwxRoomSelectLayer = KwxSecondBase.extend({
    mGameNames : null,
    mKwxRoomCreateLayer : null,
    ctor : function () {
        this._super();
        this.loadSecondCCS("res/ccs/KwxRoomSelectLayer.json");
        this.setTitleText("res/ccs/hall_second/text/text_chuangjianfangjian.png");
        this.mGameNames = ["kwx", "nn", "gsbdx", "psz", "whmj", "dzpk", "dtj", "pdk"];

        this.mKwxRoomCreateLayer = new KwxRoomCreateLayer(this.mGameNames, this);
        this.mKwxRoomCreateLayer.setPosition(cc.p(-mo.gameSize.x / 2, -mo.gameSize.y / 2));
        this.mKwxRoomCreateLayer.setVisible(false);
        mo.seekWidgetByName(this.ccsNode, "Panel_create").addChild(this.mKwxRoomCreateLayer);

        //进入游戏
        var Panel_select = mo.seekWidgetByName(this.ccsNode, "Panel_select");
        var gameIndexs = [0, 1, 2, 3, 5, 6, 7];
        // var gameIndexs = [0, 1, 2, 3, 5, 6];
        for (var i = 0; i < gameIndexs.length; i++){
            var index = gameIndexs[i];
            var Button_game = mo.seekWidgetByName(Panel_select, "Button_game" + index);
            Button_game.setTag(index);

            var Image_text = mo.seekWidgetByName(Button_game, "Image_text");
            mo.gameHelper.loadTextureImage(Image_text, "res/ccs/hall_second/roomCreateNew/img_btn_" + this.mGameNames[index] + ".png");

            Button_game.addTouchEventListener(function(sender, type){
                if (mo.gameHelper.getIsTouchEnd(type)) {
                    this.intoGame(sender.getTag());
                }
            }, this);
        }

        //关闭
        mo.seekWidgetByName(this.ccsNode, "Button_return").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEndMenuClose(type)) {
                this.setVisible(false);
            }
        }, this);
    },

    intoGame : function(gameIndex){
        if (gameIndex == 10){
            // var toTime = mo.gameHelper.getMillisecond() + 10000;
            // this.shibai = 0;
            // while (toTime > mo.gameHelper.getMillisecond()){
            //     this.shibai++;
            //     if (this.shibai % 100000 == 0){
            //         cc.log("失败次数:" + this.shibai);
            //     }
            // }
            // cc.log("尝试了:" + this.shibai);

            return;
            var configJson = {};
            configJson.ruleid = 1;
            configJson.basepoint = 1;
            configJson.maxpan = 2;
            configJson.hosttype = 1;
            configJson.vip = 0;
            configJson.pwd = 0;
            configJson.lod = 0;
            var config = JSON.stringify(configJson);
            mo.gameMsgManager.sendJoinFreeRequestpdk(mo.gameUserInfo.uid, -1, config);
            return;
        }

        this.mKwxRoomCreateLayer.onIntoGameIndex(gameIndex);
        this.mKwxRoomCreateLayer.setVisible(true);
    }
});